﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tools.Core
{
    public class Kits
    {
        public static void WriteObject<T>(T t,string path=null)
        {
            if(path==null)
                File.WriteAllText($"Data/{typeof(T).Name}.json", JsonConvert.SerializeObject(t));
            else
                File.WriteAllText(path, JsonConvert.SerializeObject(t));
        }

        public static T ReadObject<T>(string path=null)
        {
            if(path==null)
                return JsonConvert.DeserializeObject<T>(File.ReadAllText($"Data/{typeof(T).Name}.json"));
            else
                return JsonConvert.DeserializeObject<T>(File.ReadAllText(path));
        }
    }
}
